﻿#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string addStrings(string num1, string num2)
    {
        int size = num1.size() + num2.size();
        string result;
        result.reserve(size + 1);
        int begin1 = num1.size() - 1;
        int begin2 = num2.size() - 1;
        int value1 = 0;
        int value2 = 0;
        int Carry_Bit = 0;
        while (begin1 >= 0 || begin2 >= 0)
        {
            if (begin1 >= 0)
                value1 = num1[begin1--] - '0';
            else
                value1 = 0;

            if (begin2 >= 0)
                value2 = num2[begin2--] - '0';
            else
                value2 = 0;

            int num3 = value1 + value2 + Carry_Bit;
            Carry_Bit = 0;
            if (num3 >= 0)
            {
                Carry_Bit = num3 / 10;
                num3 %= 10;
            }
            result.insert(0, 1, num3 + '0');
        }
        if (Carry_Bit != 0)
        {
            result.insert(0, 1, Carry_Bit + '0');
        }
        return result;
    }
};


